package com.kk.memento;

/**
 * @author o_o
 * @date 2022-06-19
 */
public class Client {
    public static void main(String[] args) {

        Originator originator = new Originator();
        CareTaker careTaker = new CareTaker();

        //设置状态，保存
        originator.setState("zt1 hp:100");
        //添加到备忘录状态列表
        careTaker.add(originator.saveMemento());

        //设置状态，保存
        originator.setState("zt2 hp:60");
        //添加到备忘录状态列表
        careTaker.add(originator.saveMemento());


        //设置状态，保存
        originator.setState("zt3 hp:30");
        //添加到备忘录状态列表
        careTaker.add(originator.saveMemento());

        System.out.println("当前状态: " + originator.getState());

        originator.getStateFromMemento(careTaker.getMementoByIndex(0));
        System.out.println("恢复状态1: " + originator.getState());

        originator.getStateFromMemento(careTaker.getMementoByIndex(1));
        System.out.println("恢复状态2: " + originator.getState());

        originator.getStateFromMemento(careTaker.getMementoByIndex(2));
        System.out.println("恢复状态3: " + originator.getState());
    }
}
